#!/usr/bin/env node

const http = require('http'),
    fs = require('fs'),
    chalk = require('chalk'),
    log = console.log;

http.createServer((req,res) => {
    log(`${req.method} ${req.url} http:${req.httpVersion}`);
    log('req的header是：',req.headers);
    let file = __dirname + req.url;
    log(chalk.greenBright(file));
    fs.readFile(file,(err,data) => {
        if(err){
            log(err.message);
            res.statusCode = 404;
            res.end(err.message);
        }else{
            res.end(data);
        }
    });
    /* fs.createReadStream().pipe(res);*/
    //log(file);
    //res.write('hello');
    /*res.end(fs.readFileSync(file).toString('uft8'));*/
}).listen(8080);

